package sfsoftware.game.actor.item;

import sfsoftware.game.actor.attributes.Collidable;
import sfsoftware.game.actor.attributes.Obtainable;
import sfsoftware.game.trevor.Player;
import sfsoftware.util.Actor;
import sfsoftware.util.Clock;
import sfsoftware.util.Sound;
import sfsoftware.util.graphics.Graphics;

public class Heart extends Actor implements Obtainable {
	private boolean bloat = false;
	private float heartBloat = 1.20f;
	private Clock bloatTimer = new Clock(140);	
	
	public Heart(int destX, int destY, String texture, int destWidth, int destHeight) {
		super(destX, destY, texture, destWidth, destHeight);		
	}

	@Override
	public void collisionResult(Collidable object) {
		Sound.playSound("health");
		// Hearts should recover 20% health
		Player.heal((int) (Player.getMaxHealth() * 0.2f));
	}	
	
	@Override
	public void draw()
	{
		if(bloatTimer.updateClock())
		{
			bloat = !bloat;
		}
		
		if(bloat)
		{
			int newX = (int) ((getX() + (getWidth() / 2)) - ((getWidth() * heartBloat) / 2));
			int newY = (int) ((getY() + (getHeight() / 2)) - ((getHeight() * heartBloat) / 2));				
			int newWidth = (int) (getWidth() * heartBloat);
			int newHeight = (int) (getHeight() * heartBloat);
		
			Graphics.drawSprite(newX, newY, getTexture(), newWidth, newHeight, getSrcX(), getSrcY(), getWidth(), getHeight(), 1, 0, 0, 1);
		}
		else
		{
			super.draw();
		}
	}
	
}
